<?php
/**
 * create to 2021/6/24 14:38
 */

namespace app\mainadmin\controller;


use app\AdminController;
use app\mainadmin\model\SettingsModel;

/**
 * 基础设置
 * Class Index
 * @package app\store\controller
 */
class System extends AdminController
{
    /*------------------------------------------------------ */
    //-- 优先执行
    /*------------------------------------------------------ */
    public function initialize(){
        parent::initialize();
        $this->Model = new SettingsModel();
    }
    /*------------------------------------------------------ */
    //-- 主页
    /*------------------------------------------------------ */
    public function index() {
        $setting = $this->Model->where(array('name'=>'system_setting'))->find();
        $arr = json_decode($setting['data'],true);
        $this->assign('setting',$arr);
        return $this->fetch();
    }

    /*------------------------------------------------------ */
    //-- 保存配置
    /*------------------------------------------------------ */
    public function save(){
        $set = input('post.');
        if (empty($set['minimum_limit_of_bonus_points'])){
            $set['minimum_limit_of_bonus_points'] = 0;
        }
        if (empty($set['integral_value'])){
            $set['integral_value'] = 0;
        }
        $save_data = json_encode($set);
        //支付相关处理
        $res = $this->Model->where('name','system_setting')->update(['data'=>$save_data]);
        if ($res == false) return $this->error();
        return $this->success('设置成功.');
    }
}